package com.pig4cloud.pigx.contract.api.v1.websocket.handler;

import com.pig4cloud.pigx.common.customize.api.annotation.OpenApi;
import com.pig4cloud.pigx.common.websocket.handler.JsonMessageHandler;
import com.pig4cloud.pigx.contract.api.v1.websocket.manager.OpenApiWsManagerV1;
import com.pig4cloud.pigx.contract.api.v1.websocket.message.OpenApiUnSubscribeMessageV1;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

@Slf4j
@Component
@AllArgsConstructor
@OpenApi(version = "1")
public class OpenApiUnSubscribeHandlerV1 implements JsonMessageHandler<OpenApiUnSubscribeMessageV1> {

	@Autowired
	private OpenApiWsManagerV1 wsManager;

	@Override
	public void handle(WebSocketSession session, OpenApiUnSubscribeMessageV1 message) {
		wsManager.unsubscribe(session, message);
	}

	@Override
	public String type() {
		return OpenApiUnSubscribeMessageV1.TYPE;
	}

	@Override
	public Class<OpenApiUnSubscribeMessageV1> getMessageClass() {
		return OpenApiUnSubscribeMessageV1.class;
	}

}
